package com.wechat.utils.beans;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * Created by Administrator on 2016/11/22.
 */
public class ApiBean implements Serializable{


    private int code;

    private String msg;

    private String domain;//域名

    private Object data;

    public ApiBean() {
    }

    public ApiBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    @Override
    public String toString() {

       return JSONObject.toJSONString(this);
    }


    public static ApiBean responseSuccess(){
        return responseSuccess("","");
    }
    public static ApiBean responseSuccess(String msg,Object data){
        ApiBean apiBean=new ApiBean();
        apiBean.setCode(0);
        apiBean.setData(data);
        apiBean.setMsg(msg);
        return apiBean;
    }

    public static ApiBean responseSuccess(String msg){
        return responseSuccess(msg,"");
    }

    public static ApiBean responseError(String msg,Object data){
        ApiBean apiBean=new ApiBean();
        apiBean.setCode(1);
        apiBean.setData(data);
        apiBean.setMsg(msg);
        return apiBean;
    }

    public static ApiBean responseArgsError(){
        return responseError("参数错误","");
    }

    public static ApiBean responseError(){
        return responseError("","");
    }

    public static ApiBean responseError(String msg){
        return responseError(msg,"");
    }

    public static ApiBean responseNotLogin(){
        ApiBean apiBean=new ApiBean();
        apiBean.setCode(-1);
        apiBean.setMsg(ApiMsg.LOGIN_ERROR);
        return apiBean;
    }
}
